package com.amos.wx.listener;

import com.amos.wx.handler.SubscribeEventMessageHandler;
import com.amos.wx.mp.event.ReceiveMessageEvent;
import com.amos.wx.mp.handler.MessageHandlerFactory;
import com.amos.wx.mp.model.message.Message;
import com.amos.wx.mp.model.message.SubscribeEventMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author Amos
 * @ClassName ReceiveMessageEventListener
 * @Description TODO
 * @Date 2018/11/26 21:04
 * @VERSION 1.0
 **/
@Component
public class ReceiveMessageEventListener implements ApplicationListener<ReceiveMessageEvent> {
    @Autowired
    private MessageHandlerFactory messageHandlerFactory;
    @Async
    @Override
    public void onApplicationEvent(ReceiveMessageEvent receiveMessageEvent) {
        Message message = (Message) receiveMessageEvent.getSource();
        if (message instanceof SubscribeEventMessage){
            new SubscribeEventMessageHandler(messageHandlerFactory);
        }
    }
}
